﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Expo;
using Base;
using MarketSales;


public partial class Member_MarketSales_MarketSalesEdit : nspBase.MemberBasePge
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!CheckCookies())
        {
            Response.Redirect("../../login/login.aspx");
            return;
        }
        else
        {
            if (!IsPostBack)
            {
                ExpoTypeBind();
                Bind();
            }
        }
    }
    private void ExpoTypeBind()
    {
        IExpoType RExpoType = new RExpoType();
        DataTable dt = RExpoType.GetDataTable();
        dropTypeID.DataSource = dt.DefaultView;
        dropTypeID.DataValueField = "ID";
        dropTypeID.DataTextField = "Type";
        dropTypeID.DataBind();
    }
    private void Bind()
    {
        int id = 0;
        if (Request.QueryString["ID"] != null)
        {
            id = int.Parse(Request.QueryString["ID"].ToString());
        }
        IMarketSales RMarketSales = new RMarketSales();
        TMarketSales TMarketSales = RMarketSales.GateItem(id);
        txtTitle.Text = TMarketSales.Title;
        dropTypeID.SelectedValue = TMarketSales.TypeID.ToString();
        txtStartDate.Text = TMarketSales.StartDate.ToShortDateString();
        txtEndDate.Text = TMarketSales.EndDate.ToShortDateString();
        txtPlace.Text = TMarketSales.Place;
        txtAuthorize.Text = TMarketSales.Authorize;
        txtFrontFor.Text = TMarketSales.FrontFor;
        txtUndertake.Text = TMarketSales.Undertake;
        txtAidance.Text = TMarketSales.Aidance;
        txtSummary.Text = TMarketSales.Summary;
        txtRange.Text = TMarketSales.Range;
        dropPeriod.SelectedValue = TMarketSales.Period;
        dropExpoType.SelectedValue = TMarketSales.ExpoType;
        txtHomepage.Text = TMarketSales.Homepage;
        ImgUrl.Src = TMarketSales.Picture;
        ImgUrl1.Value = TMarketSales.Picture;
        txtShowArea.Text = TMarketSales.ShowArea.ToString();
        txtBusinessmen.Text = TMarketSales.Businessmen.ToString();
        txtSpectator.Text = TMarketSales.Spectator.ToString();
        txtPrice.Text = TMarketSales.Price.ToString();
        txtMinNum.Text = TMarketSales.MinNum.ToString();
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            int id = 0;
            if (Request.QueryString["ID"] != null)
            {
                id = int.Parse(Request.QueryString["ID"].ToString());
            }
            TMarketSales TMarketSales = new TMarketSales();
            TMarketSales.ID = id;
            TMarketSales.Title = txtTitle.Text;
            TMarketSales.TypeID = int.Parse(dropTypeID.SelectedValue);
            TMarketSales.StartDate = Convert.ToDateTime(txtStartDate.Text);
            TMarketSales.EndDate = Convert.ToDateTime(txtEndDate.Text);
            TMarketSales.Place = txtPlace.Text;
            TMarketSales.Authorize = txtAuthorize.Text;
            TMarketSales.FrontFor = txtFrontFor.Text;
            TMarketSales.Undertake = txtUndertake.Text;
            TMarketSales.Aidance = txtAidance.Text;
            TMarketSales.Summary = txtSummary.Text;
            TMarketSales.Range = txtRange.Text;
            TMarketSales.Period = dropPeriod.SelectedValue;
            TMarketSales.ExpoType = dropExpoType.SelectedValue;
            TMarketSales.Homepage = txtHomepage.Text;
            TMarketSales.Picture = ImgUrl1.Value;
            TMarketSales.ShowArea = int.Parse(txtShowArea.Text);
            TMarketSales.Businessmen = int.Parse(txtBusinessmen.Text);
            TMarketSales.Spectator = int.Parse(txtSpectator.Text);
            TMarketSales.Price = int.Parse(txtPrice.Text);
            TMarketSales.MinNum = int.Parse(txtMinNum.Text);
            IMarketSales RMarketSales = new RMarketSales();
            RMarketSales.Update(TMarketSales);
            ShowMessage("市场展销信息修改成功！", "MarketSales/MarketSalesList.aspx");
        }
        catch (Exception ex)
        {
            ShowMessage("市场展销信息修改失败！", "MarketSales/MarketSalesList.aspx");
        }
    }

    protected void btnBace_Click(object sender, EventArgs e)
    {
        Response.Write("<script> window.location.href='MarketSalesList.aspx'</script>");
    }
}
